/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>投诉管理</h3>
        <h5>商城对商品交易投诉管理及仲裁</h5>
      </div>
      <ul class="tab-base nc-row">
        <router-link :to="{name:'complains', params:{state:1}}">
          <li>
            <a>
              <span>新投诉</span>
            </a>
          </li>
        </router-link>
        <router-link :to="{name:'complains', params:{state:2}}">
          <li>
            <a>
              <span>对话中</span>
            </a>
          </li>
        </router-link>
        <router-link :to="{name:'complains', params:{state:3}}">
          <li>
            <a>
              <span>待仲裁</span>
            </a>
          </li>
        </router-link>
        <router-link :to="{name:'complains', params:{state:4}}">
          <li>
            <a>
              <span>已完成</span>
            </a>
          </li>
        </router-link>
        <router-link :to="{name:'complain_subject'}" active-class="current">
          <li>
            <a>
              <span>主题设置</span>
            </a>
          </li>
        </router-link>
        <router-link :to="{name:'complain_time'}">
          <li>
            <a>
              <span>时效设置</span>
            </a>
          </li>
        </router-link>
      </ul>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>商家主题列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <a @click="toAdd()">
        <div class="fbutton">
          <div class="add">
            <span>
              <i class="fa fa-plus"></i>新增数据
            </span>
          </div>
        </div>
      </a>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
    </div>

    <div class="tablebox">
      <el-table :data="tableData" style="width: 100%;">
        <el-table-column label="投诉主题" prop="subject_name" width="180" show-overflow-tooltip></el-table-column>
        <el-table-column label="投诉主题描述" prop="subject_desc" width="180"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button size="small" icon="el-icon-delete" @click="delFn(scope.row.subject_id)">删除</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getComplainSubjectPage, deleteSubject } from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      getComplainSubjectPage({
        page: this.currentPage,
        size: this.pageSize
      }).then(function(res) {
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    refresh() {
      this.getPage();
      this.$message.success("刷新成功！");
    },
    toAdd() {
      this.$router.push({
        name: "add_subject"
      });
    },
    delFn(id) {
      var that = this;
      this.$confirm("是否删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteSubject(id).then(function(res) {
            if (res.status == 1) {
              that.$message.success("删除成功!");
              that.getPage();
            } else {
              that.$message.error("操作失败");
            }
          });
        })
        .catch(() => {
          this.$message.info("已取消删除");
        });
    }
  }
};
</script>

<style scoped>
</style>
